/*
 * ***********************************************************
 * @Project: SCVHDemo
 * @File: MessageUtil.java
 * @LastEditTime: 2024/11/17 15:07:42
 * @Author: chadm
 * ***********************************************************
 */

package com.example.ipclibrary;

import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceControlViewHost;

public class MessageUtil {
    private static final String TAG = MessageUtil.class.getSimpleName();

    public static final int MSG_REG_CLIENT = 1;
    public static final int MSG_SEND_SURFACE_INFO = 2;
    public static final int MSG_REC_SUBPACKAGE = 3;
    public static final int MSG_TOUCH_EVENT = 4;

    public static final String KEY_HOST_TOKEN= "host_token";
    public static final String KEY_CLIENT_PACKAGE = "client_package";
    public static final String KEY_DISPLAY_ID = "display_id";
    public static final String KEY_WIDTH = "width";
    public static final String KEY_HEIGHT = "height";
    public static final String KEY_SURFACE_PACKAGE = "surface_package";
    public static final String KEY_TOUCH_EVENT = "touch_event";

    /**
     *
     * @param pkg
     * @return
     */
    public static Message obtainRegClient(String pkg) {
        Message msg = Message.obtain();
        msg.what = MSG_REG_CLIENT;
        Bundle bundle = msg.getData();
        bundle.putString(KEY_CLIENT_PACKAGE,pkg);
        return msg;
    }

    /**
     *
     * @param hostToken
     * @param displayId
     * @param w
     * @param h
     * @return
     */
    public static Message obtainSurfaceInfo(IBinder hostToken,int displayId,int w,int h) {
        Message msg = Message.obtain();
        msg.what = MSG_SEND_SURFACE_INFO;
        Bundle bundle = msg.getData();
        bundle.putBinder(KEY_HOST_TOKEN,hostToken);
        bundle.putInt(KEY_DISPLAY_ID,displayId);
        bundle.putInt(KEY_HEIGHT,h);
        bundle.putInt(KEY_WIDTH,w);
        return msg;
    }

    public static Message obtainSurfacePackage(SurfaceControlViewHost.SurfacePackage pkg, String appName) {
        Message msg = Message.obtain();
        msg.what = MSG_REC_SUBPACKAGE;
        if(pkg != null) {
            Bundle bundle = msg.getData();
            bundle.putParcelable(KEY_SURFACE_PACKAGE,pkg);
            bundle.putString(KEY_CLIENT_PACKAGE,appName);
        } else {
            Log.e(TAG,"surface package can not be null!");
        }
        return msg;
    }

    public static Message obtainTouchEvent(MotionEvent event) {
        Message msg = Message.obtain();
        msg.what = MSG_TOUCH_EVENT;
        Bundle bundle = msg.getData();
        bundle.putParcelable(KEY_TOUCH_EVENT,event);
        return msg;
    }




}
